<template>
    <div class="merchandise-categories-add views-container" v-loading = "loading">
        <el-dialog width="45%" :visible.sync="dialogListVisible" @close="clearData" custom-class="reset-pwd wlm-form-dialog dialog-table" style="margin-top: -10vh;">
      <div class="wlm-form" v-if="dialogListVisible" style="margin-bottom:0">
        <div class="wlm-form-header wlm-dialog-fixheader">
          <span class="wlm-dialog-inlenr">{{formType=='1'?'商家列表':'门店列表'}}</span>
        </div>
        <!-- <el-scrollbar wrap-class="scrollbar-wrapper"> -->
        <div class="wlm-table-header" style="margin-bottom:-20px;margin-top:14px;">
          <el-form :model="tableFormatData.userTable.files" size="small" label-width="110px" class="retail-form" label-position="right">
            <el-form-item label="" class="filter" label-width="10px">
              <el-form-item class="search">
                <el-input v-model="tableFormatData.userTable.files.name" placeholder="请输入名称" style="width:200px;margin-left:25px;"></el-input>
                <el-button style="margin-left:10px;" type="primary" @click="filesSerch">搜索</el-button>
              </el-form-item>
            </el-form-item>
          </el-form>
        </div>
        <el-table :row-class-name="tableRowClassName" v-loading="!isTableFormatGetEnd" v-if="formType=='1'" class="chooseTable" :data="tableFormatData.userTable.tableData" :row-style="{cursor:'pointer'}" @row-click="merchantRowClick" highlight-current-row style="width: 100%;padding:0 30px;border-bottom:none">
          <el-table-column prop="date" label="商家名称">
            <template slot-scope="scope">
              <p>{{scope.row.name}}</p>
            </template>
          </el-table-column>
          <el-table-column prop="date" label="门店数量">
            <template slot-scope="scope">
              <p>{{scope.row.storenum}}</p>
            </template>
          </el-table-column>
          <el-table-column prop="date" label="成为时间">
            <template slot-scope="scope">
              <p>{{scope.row.create_time}}</p>
            </template>
          </el-table-column>
        </el-table>
        <el-table ref="multipleTable" v-loading="!isTableFormatGetEnd" v-if="formType=='2'" class="chooseTable" @selection-change="storeChange" :data="tableFormatData.userTable.tableData" style="width: 100%;padding:0 30px;border-bottom:none">
          <el-table-column type="selection" width="55">
          </el-table-column>
          <el-table-column prop="date" label="门店名称">
            <template slot-scope="scope">
              <p>{{scope.row.name}}</p>
            </template>
          </el-table-column>
          <el-table-column prop="date" label="店员数量">
            <template slot-scope="scope">
              <p>{{scope.row.menum}}</p>
            </template>
          </el-table-column>
          <el-table-column prop="date" label="成为时间">
            <template slot-scope="scope">
              <p>{{scope.row.create_time*1000 | parseTime('{y}-{m}-{d} {h}:{i}:{s}')}}</p>
            </template>
          </el-table-column>
        </el-table>
        <div class="pagination-content flex-row flex-justify-e flex-align-c" style="padding-right: 20px;height:60px;">
          <el-pagination :disabled="!hasTableData" @size-change="listPageChange" @current-change="listPageChange" :current-page.sync="tableFormatData.userTable.pagination.page" :page-sizes="tableFormatData.userTable.pagination.pagesizes" :page-size.sync="tableFormatData.userTable.pagination.list_rows" layout="total, sizes, prev, pager, next, jumper" :total="hasTableData?tableFormatData.userTable.pagination.total : 0">
          </el-pagination>
        </div>
        <!-- </el-scrollbar> -->
      </div>
      <footer class="flex-row flex-align-c flex-justify-c wlm-dialog-fixfooter">
        <el-button size="small" type="primary" @click="dialogListVisible = false">确定</el-button>
      </footer>
        </el-dialog>
       
       
        <div class="wlm-form">
                <div class="wlm-form-header">基本设置</div>
                <div class="wlm-form-content">
                    <el-form ref="basicset" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="200px" class="retail-form" label-position="right">
                        <el-form-item label="活动名称" prop="title"> 
                            <el-input v-model.trim="formFormatData.formData.title"></el-input>
                        </el-form-item>
                        <el-form-item label="活动时间" prop="time">
                            <el-date-picker :picker-options="pickerOptions" style="width:360px;" :default-time="[`${new Date().getHours()}:${(new Date().getMinutes() + 5).toString().padStart(2,'0')}:00`,'23:59:59']"  v-model="formFormatData.formData.time" value-format="timestamp" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" >
                            </el-date-picker>
                        </el-form-item>
                        <el-form-item label="活动渠道" prop="source" :rules="[{ required: true, message: '请选择渠道', validator: validateCheckArray, trigger: 'change' }]">
                                <el-checkbox-group v-model="formFormatData.formData.source">
                                <el-checkbox label="2" v-if="JSON.stringify($store.getters.power).indexOf('wxapp')>-1">微信小程序</el-checkbox>
                                    <el-checkbox label="3" v-if="JSON.stringify($store.getters.power).indexOf('H5')>-1">H5</el-checkbox>
                                    <el-checkbox label="4" v-if="JSON.stringify($store.getters.power).indexOf('wechat')>-1">微信公众号</el-checkbox>
                                    <el-checkbox label="7" v-if="JSON.stringify($store.getters.power).indexOf('aliapp')>-1">支付宝小程序</el-checkbox>
                                    <el-checkbox label="9" v-if="JSON.stringify($store.getters.power).indexOf('toutiaoapp')>-1">抖音-头条</el-checkbox>
                                </el-checkbox-group>
                        </el-form-item>
                         <el-form-item label="背景音乐" prop="time">
                              <choose-files ref="chooseFiles" :config="choosePlatmaginConfig" :changeEvt="formFormatFiltersChange"></choose-files>
                        </el-form-item>
                         <el-form-item label="活动封面图" prop="time">
                              <choose-files ref="chooseFiles" :config="choosePlatformConfig" :changeEvt="formFormatFiltersChange"></choose-files>
                                 <div class="form-help">建议尺寸：400*400像素</div>
                        </el-form-item>
                         <el-form-item label="小程序分享主图" prop="time">
                              <choose-files ref="chooseFiles" :config="choosePlatsappConfig" :changeEvt="formFormatFiltersChange"></choose-files>
                           <div class="form-help">建议尺寸：500*400像素</div>
                                
                        </el-form-item>
                         <el-form-item label="图文分享主图" prop="time">
                           <choose-files ref="chooseFiles" :config="choosePlatwechatConfig" :changeEvt="formFormatFiltersChange"></choose-files>
                            <div class="form-help">建议尺寸：100*100像素</div>
                        </el-form-item>
                         <el-form-item label="图文分享描述" prop="time">
                            <el-input  v-model.trim="formFormatData.formData.praise_wechat_text">
                            </el-input>
                        </el-form-item>
                        <el-form-item label="是否开启虚拟浏览量" prop="time">
                            <el-radio-group v-model="formFormatData.formData.is_false_look">
                                <el-radio :label="1">是</el-radio>
                                <el-radio :label="2">否</el-radio>
                            </el-radio-group>
                        </el-form-item>
                         <el-form-item label="随机增加虚拟浏览量" prop="time" v-if="formFormatData.formData.is_false_look==1">
                            <el-input  v-model.trim="formFormatData.formData.false_look_rand" >
                            </el-input>
                            <div class="form-help">格式1|10随机最小值|随机最大值，0为不设置浏览量</div>
                        </el-form-item>
                         <el-form-item label="虚拟基础浏览量" prop="time" v-if="formFormatData.formData.is_false_look==1">
                            <el-input-number  v-model.trim="formFormatData.formData.false_look_num" :controls="false">
                            </el-input-number>
                        </el-form-item>
                         <el-form-item label="是否开启虚拟转发量" prop="time">
                            <el-radio-group v-model="formFormatData.formData.is_false_forward">
                                <el-radio :label="1">是</el-radio>
                                <el-radio :label="2">否</el-radio>
                            </el-radio-group>
                        </el-form-item>
                         <el-form-item label="随机增加虚拟转发量" prop="time" v-if="formFormatData.formData.is_false_forward==1">
                            <el-input  v-model.trim="formFormatData.formData.false_forward_rand" >
                            </el-input>
                            <div class="form-help">格式1|10随机最小值|随机最大值，0为不设置浏览量</div>
                        </el-form-item>
                         <el-form-item label="虚拟基础转发量" prop="time" v-if="formFormatData.formData.is_false_forward==1">
                            <el-input-number  v-model.trim="formFormatData.formData.false_forward_num" :controls="false">
                            </el-input-number>
                        </el-form-item>
                         <el-form-item label="虚拟人数" prop="time" >
                            <!-- <el-input  v-model.trim="formFormatData.formData.false_user_num">
                            </el-input> -->
                              <el-input-number  v-model.trim="formFormatData.formData.false_user_num" :controls="false">
                            </el-input-number>
                        </el-form-item>
                        <el-form-item label="搭配商品">
                            <choose-goods ref="chooseGoods" :config="chooseGoodsConfig" :changeEvt="filtersChange"></choose-goods>
                            <el-button type="primary" @click="goodsToogle">选择商品</el-button>
                            <div style="height:10px;"></div>
                            <el-table v-if="formFormatData.formData.goods != ''" :data="formFormatData.formData.goods" style="width: 100%;">
                                <el-table-column  label="商品">
                                    <template slot-scope="scope">
                                    <div class="flex-row">
                                        <!-- {{scope.row.}} -->
                                         <img class="logo" v-if="scope.row.goods.image && scope.row.goods.image" :src="scope.row.goods.image[0]['file_path']">
                                        <!-- <img class="logo" :src="scope.row.goods.image[0]['file_path']"> -->
                                        <div class="inner-text">
                                        <p>{{scope.row.goods.goods_name}}</p>
                                        </div>
                                    </div>
                                    </template>
                                </el-table-column>
                                <el-table-column label="操作">
                                    <template slot-scope="scope">
                                    <div class="operation-group">
                                        <el-button  class="wlm-text" type="text" @click="deleteTable(scope)">删除</el-button>
                                    </div>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </el-form-item>
                        <el-form-item label="是否强制关注公众号" prop="is_subscribe">
                            <el-radio-group v-model="formFormatData.formData.is_subscribe">
                                <el-radio :label="1">是</el-radio>
                                <el-radio :label="2">否</el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <el-form-item label="参与人群" prop="user_group">
                            <el-radio-group v-model="formFormatData.formData.user_group">
                                <el-radio :label="1">所有用户可参与</el-radio>
                                <el-radio :label="2">仅会员可参与</el-radio>
                                <el-radio :label="3">分销用户</el-radio>
                                <el-radio :label="4">新用户</el-radio>
                                <el-radio :label="5">限定地区用户</el-radio>
                                <el-radio :label="6" >标签用户</el-radio>
                                <el-select v-model="formFormatData.formData.label_ids" multiple placeholder="请选择标签用户"  collapse-tags v-if="formFormatData.formData.user_group==6">
                                    <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value.toString()"></el-option>
                                </el-select>
                            </el-radio-group>
                        </el-form-item>
                        <el-form-item label="地区信息" v-if="formFormatData.formData.user_group=='5'" prop="address">
                            <el-input  v-model.trim="formFormatData.formData.address">
                            </el-input>
                            <p class="form-help">如果您希望仅限成都和重庆地区的用户参加抽奖，则填入成都、重庆，地区仅限市级地区</p>
                        </el-form-item>
                        <el-form-item label="选择社群">
                            <el-select v-model="formFormatData.formData.community" multiple placeholder="请选择社群" style="width:200px;" >
                                <el-option v-for="item in selectValue" :key="item.id" :label="item.title" :value="item.id" ></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="活动内容">
                             <ueditor
                                v-if="isFirst"
                                :ueditorChange="shopInfoChange"
                                :ueditorList="ueditorList"
                                :bindIndex="1"
                                :defaultMsg='defaultMsg1'
                                :config='{initialFrameWidth: null,initialFrameHeight: 350}'
                                ref="by_know"></ueditor>
                        </el-form-item>
                    </el-form>
            </div>
        </div>
         <div class="wlm-form">
                <div class="wlm-form-header">标签设置</div>
                <div class="wlm-form-content">
                    <el-table :data="formFormatData.formData.label" style="width:100%;" >
                        <el-table-column label="点赞数">
                            <template slot-scope="scope">
                                <el-input-number size="mini" :controls="false" :min="0" v-model="scope.row.praise_num" placeholder="请输入点赞数"></el-input-number>
                            </template>
                        </el-table-column>
                        <el-table-column label="选择标签">
                            <template slot-scope="scope">
                                <el-select v-model="scope.row.label_ids" multiple placeholder="请选择" > 
                                    <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value.toString()">
                                    </el-option>
                                </el-select>
                            </template>
                        </el-table-column>
                        <el-table-column label="操作">
                            <template slot-scope="scope">
                                <el-button type="text" @click="delbtn(scope)" size="small">删除</el-button>
                            </template>
                            </el-table-column>
                    </el-table>
                    <el-button type="primary" @click="tagbtn">添加标签</el-button>
                    <div style="margin-top:20px; color:#bbb;">在活动过程中给指定达到点赞数的用户打上定义标签</div>
                </div>
            </div>
           <div class="wlm-form">
                <div class="wlm-form-header">奖品设置</div>
                <div class="wlm-form-content">
                    <el-form ref="active" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="200px" class="retail-form" label-position="right">
                        <el-form-item label="是否开启满多少赞赠送优惠券">
                            <el-radio-group v-model="formFormatData.formData.is_coupon">
                                <el-radio :label="1">是</el-radio>
                                <el-radio :label="2">否</el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <el-form-item v-if="formFormatData.formData.is_coupon==1">
                            <div v-for="(item,index) in formFormatData.formData.coupon" :key="index" style="display:flex;padding-bottom:10px;">
                                <div style="padding-right:15px; min-width:57px">点赞达</div>
                                <el-input-number placeholder="请输入内容" v-model="item.praise_number" :controls="false">
                                    <!-- <el-button slot="append" icon="el-icon-top"></el-button> -->
                                </el-input-number>
                                <div style="padding:0 15px;min-width:100px;">赠送优惠券</div>
                                <el-select v-model="item.coupon_id" placeholder="请选择">
                                    <el-option v-for="item1 in couponTypeList" :key="item1.coupon_id"  :label="item1.name" :value="item1.coupon_id">
                                        <!-- {{item1}} -->
                                    </el-option>
                                </el-select>
                                <div style="padding:0 15px;min-width:100px;">赠送数量</div>
                                 <el-input-number placeholder="请输入内容" v-model="item.count" :controls="false" :min="1">
                                </el-input-number>
                                <el-button style="margin-left:10px;" icon="el-icon-delete" circle plain @click="delMeal(index)"></el-button>
                            </div>
                            <el-button @click="addPrizeClick" type="text">新增优惠劵礼品项</el-button>
                        </el-form-item>
                        <el-form-item label="奖品总价值">
                             <el-input-number  :controls="false" v-model.trim="formFormatData.formData.prize_price">
                             </el-input-number>
                        </el-form-item>
                        <el-form-item label="奖品模式">
                            <el-radio-group v-model="formFormatData.formData.type">
                                <el-radio :label="1">名次模式</el-radio>
                                <el-radio :label="2">点赞数模式</el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <el-form-item v-if="formFormatData.formData.type == 1">
                            <div style="display:flex;">
                                <div class="like-font-before">点赞前</div>
                                    <el-input-number v-model="formFormatData.formData.rank" placeholder="请输入数字" :min="1" :max="100" :controls="false" style="margin-left:10px;">
                                        <template slot="append">名</template>
                                    </el-input-number>
                                <div class="like-font" style="margin-left:10px;">可获奖</div>
                            </div>
                            <div class="form-help">注：最大限制100名</div>
                        </el-form-item>
                    </el-form>
                    <choose-files ref="chooseFiles" :config="chooseFilesImages" :changeEvt="uploadChange" style="display:none;"></choose-files>
                    <div class="form-help" style="margin-left:10px;">奖品图片建议尺寸：100*100</div>
                    <div class="wlm-form-content" v-if="formFormatData.formData.type == 1">
                        <el-table :data="formFormatData.formData.prize" style="width:100%;">
                            <el-table-column label="名次" width="320">
                                <template slot-scope="scope">
                                    <el-select v-model="scope.row.number" size="mini" style="width:100%" @remove-tag="rankingbtn($event,scope.row.ranking)">
                                        <el-option v-for="item in rankingList" :key="item.value" :label="item.label" :value="item.value"></el-option>
                                    </el-select>
                                </template>
                            </el-table-column>
                              <el-table-column label="奖品图片">
                                <template slot-scope="scope">
                                    {{scope.row.image.file_path}}
                                    <!-- :src="scope.row.image&&scope.row.image.length? scope.row.image[0]['file_path'] :''" -->
                                    <img class="update-load"  v-if="scope.row.image" :src="scope.row.image&&scope.row.image.length? scope.row.image[0]['file_path'] :''"  width="50" height="50" @click="uploadColumn(scope.$index)" />
                                    <div v-else class="flex-row flex-align-c flex-justify-c update-load" @click="uploadColumn(scope.$index)">
                                        <i class="el-icon-plus avatar-uploader-icon"></i>
                                    </div>
                                </template>
                            </el-table-column>
                            <el-table-column label="奖品名称">
                                <template slot-scope="scope">
                                    <el-input size="mini" style="width:120px;" v-model="scope.row.title" placeholder="请输入奖品名称"></el-input>
                                </template>
                            </el-table-column>
                             <el-table-column label="奖品价值">
                                <template slot-scope="scope">
                                    <el-input-number size="mini" style="width:150px;" class="distribution_type_fenxiao120" :controls="false" v-model="scope.row.prize_money" placeholder="请输入奖品价值"></el-input-number>
                                </template>
                            </el-table-column>
                           <el-table-column label="中奖码有效期" width="270px">
                                <template slot-scope="scope">
                                     <!-- <el-radio v-model="scope.row.prize_hx_time" label="1">备选项</el-radio>
                                     <el-radio v-model="scope.row.prize_hx_time" label="1">备选项</el-radio> -->
                                     <el-radio-group v-model="scope.row.prize_hx_time_over">
                                       <el-radio  :label="1" >永久</el-radio>
                                        <!-- <el-radio :label="2" >有效时间起
                                            <el-input-number class="distribution_type_fenxiao6" :controls="false" style="width:60px;" :min="1" :step="1" step-strictly v-model="scope.row.prize_hx_time"></el-input-number>
                                            天内可使用
                                        </el-radio> -->
                                          <el-radio :label="2">有效时间起
                                            <el-input-number :controls="false" class="distribution_type_fenxiao60" style="width:60px;"  :min="1" :step="1" step-strictly  v-model="scope.row.prize_hx_time"></el-input-number>
                                            天内可使用
                                        </el-radio>
                                     </el-radio-group>
                                    
                                </template>
                            </el-table-column>
                          
                            <el-table-column label="选择商家">
                                <template slot-scope="scope">
                                    <el-button style="max-width:200px;" plain @click="showDialogSet(scope.$index)">
                                        <p style="white-space: normal;">{{scope.row.bus_id?scope.row.business_name:'选择对应奖品商家'}}</p>
                                    </el-button>
                                </template>
                            </el-table-column>
                            <el-table-column label="操作门店">
                                <template slot-scope="scope">
                                     <el-button style="max-width:220px" :disabled="!scope.row.bus_id" plain @click="showDialogSetDoor(scope.$index,scope.row.bus_id)">
                                            <p style="max-width:200px;white-space: normal;">
                                            <span v-if="scope.row.store_ids.length>0" v-for="(item, index) in scope.row.store_ids" :key="index">{{item.name}} {{scope.row.store_ids.length>1 && index != scope.row.store_ids.length-1?'/':''}}</span>
                                            <span v-if="scope.row.store_ids.length==0">选择门店</span>
                                            <!-- {{scope.row.store_ids.length>0?scope.row.storestore_name.join(' / '):'所有门店'}} -->
                                            </p>
                                        </el-button>
                                </template>
                            </el-table-column>
                            <el-table-column label="操作" >
                                <template slot-scope="scope">
                                    <el-button type="text"  size="small" @click="deleteGiftTable(scope)">删除</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                        <div class="add-lottery" style="margin-top:15px;">
                            <el-button type="primary" @click="addGiftTable">添加奖品</el-button>
                        </div>
                    </div>
                    <choose-files ref="chooseFiles" :config="chooseFilesImage" :changeEvt="uploadChange" style="display:none;"></choose-files>
                    <div class="wlm-form-content" v-if="formFormatData.formData.type == 2">
                        <el-table :data="formFormatData.formData.prize" style="width:100%;">
                            <el-table-column label="是否开启叠加">
                                <template slot-scope="scope">
                                    <el-switch 
                                    v-model="scope.row.is_superposition" 
                                    :active-value="1" 
                                    :inactive-value="2" 
                                    @change="superpositionbtn(scope.row.is_superposition)"
                                    ></el-switch>
                                </template>
                            </el-table-column>
                            <el-table-column label="点赞数">
                                <template slot-scope="scope">
                                    <el-input size="mini" style="width:120px;" v-model="scope.row.praise_num" placeholder="请输入点赞数"></el-input>
                                </template>
                            </el-table-column>
                              <el-table-column label="奖品图片">
                                <template slot-scope="scope">
                                    <!-- {{scope.row.image.file_path}} -->
                                    <img class="update-load"  v-if="scope['row']['image']" :src="scope.row.image&&scope.row.image.length? scope.row.image[0]['file_path'] :''" width="50" height="50" @click="uploadColumn(scope.$index)" />
                                    <div v-else class="flex-row flex-align-c flex-justify-c update-load" @click="uploadColumn(scope.$index)">
                                        <i class="el-icon-plus avatar-uploader-icon"></i>
                                    </div>
                                </template>
                            </el-table-column>
                            <el-table-column label="奖品名称">
                                <template slot-scope="scope">
                                    <el-input size="mini" style="width:120px;" v-model="scope.row.title" placeholder="请输入奖品名称"></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="奖品价值">
                                <template slot-scope="scope">
                                    <el-input-number size="mini" style="width:150px;" class="distribution_type_fenxiao120" v-model="scope.row.prize_money" :controls="false" placeholder="请输入奖品价值"></el-input-number>
                                </template>
                            </el-table-column>
                             <el-table-column label="奖品数量">
                                <template slot-scope="scope">
                                    <el-input-number size="mini" style="width:150px;" class="distribution_type_fenxiao120" :controls="false" v-model="scope.row.prize_num" placeholder="请输入奖品数量"></el-input-number>
                                </template>
                            </el-table-column>
                             <el-table-column label="中奖码有效期" width="270px">
                                <template slot-scope="scope">
                                     <!-- <el-radio v-model="scope.row.prize_hx_time" label="1">备选项</el-radio>
                                     <el-radio v-model="scope.row.prize_hx_time" label="1">备选项</el-radio> -->
                                     <el-radio-group v-model="scope.row.prize_hx_time_over">
                                       <el-radio  :label="1" >永久</el-radio>
                                        <el-radio :label="2">有效时间起
                                            <el-input-number :controls="false" class="distribution_type_fenxiao60" style="width:60px;"  :min="1" :step="1" step-strictly  v-model="scope.row.prize_hx_time"></el-input-number>
                                            天内可使用
                                        </el-radio>
                                     </el-radio-group>
                                </template>
                            </el-table-column>
                          
                            <el-table-column label="关联商家">
                                <!-- <template slot-scope="scope">
                                    <el-button plain v-model="scope.row.business_name" size="small">选择商家</el-button>
                                </template> -->
                                <template slot-scope="scope">
                                    <el-button style="max-width:200px;" plain @click="showDialogSet(scope.$index)">
                                        <p style="white-space: normal;">{{scope.row.bus_id?scope.row.business_name:'选择商家'}}</p>
                                    </el-button>
                                </template>
                            </el-table-column>
                            <el-table-column  label="操作门店">
                                <template slot-scope="scope">
                                    <!-- <el-button  plain v-model="scope.row.storeName" size="small">所有门店</el-button> -->
                                     <el-button style="max-width:220px" :disabled="!scope.row.bus_id" plain @click="showDialogSetDoor(scope.$index,scope.row.bus_id)">
                                            <p style="max-width:200px;white-space: normal;">
                                            <span v-if="scope.row.store_ids.length>0" v-for="(item, index) in scope.row.store_ids" :key="index">{{item.name}} {{scope.row.store_ids.length>1 && index != scope.row.store_ids.length-1?'/':''}}</span>
                                            <span v-if="scope.row.store_ids.length==0">选择门店</span>
                                            <!-- {{scope.row.store_ids.length>0?scope.row.storestore_name.join(' / '):'所有门店'}} -->
                                            </p>
                                        </el-button>
                                </template>
                            </el-table-column>
                            <el-table-column label="操作">
                                <template slot-scope="scope">
                                    <el-button type="text" @click="deleteGiftTable(scope)" size="small">删除</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                        <div style="color:#bbb;padding:20px 0">开启叠加后相应的奖品可以叠加获取，例如点赞数50且开启叠加，点赞数60开启叠加，那么点赞数达60时可以叠加获取点赞数50和60的
                             两个奖品；点赞数50且开启叠加，点赞数60不开启叠加，点赞数70开启叠加，那么点赞数达60可以获取点赞数50，60两个奖品，点赞数
                             达70可以获取点赞数50，70两个奖品，以此类推。</div>
                        <div class="add-lottery" style="margin-top:15px;">
                            <el-button type="primary" @click="addGiftTable">添加奖品</el-button>
                        </div>
                    </div>
                </div>
            </div>
           
        <div v-cloak class="wlm-fixed-btn flex-row flex-align-c flex-justify-c">
            <el-button size="small" @click="saveForm" type="primary" :loading="butt">保存</el-button>
            <router-link tag="span" to="/application/activityLike">
                <el-button size="small">返回</el-button>
            </router-link>
        </div>
    </div>
</template>

<script>
import {
    praiseSave,
    praiseDetail
} from '@/api/operation'
import {
  getUserTag,
  couponEasyList
} from '@/api/application'
import {
  servicesList,
  shopIndex
} from '@/api/merchant'

  import ChooseGoods from '@/components/ChooseGoods/index'
  import ChooseFiles from '@/components/ChooseFiles/index'
  import ueditor from '@/components/Ueditor/index'
  import { Base64 } from 'js-base64'
  import {
    businessIndex
  } from '@/api/merchant'
  import mixins from '@/mixins/mixins'
  export default {
      mixins: [mixins.getters('Form'), mixins.getters('Table')],
      components: {
        ChooseGoods,
        ChooseFiles,
        ueditor
      },
      created(){
          this.$nextTick(() => {
              this.communitybtn()
              this.luckcrowdbtn()
              this.coupontableList()
              if(this.$route.query.praise_id){
                  this.praiseDetailbtn()
              }
              
          })
      },
      data() {
          return {
            loading:false,
            butt:false,
                pickerOptions: {
                    disabledDate(time) {
                    return time.getTime() < Date.now() - 8.64e7
                    }
                },
              lastID: -1,
              options:[],
              selectValue:[],
              isFirst: false,
              ueditorList: [],
              defaultMsg1: '',
            currentRow: [],
            $lineIndex: -1,
            formType: '1',
            dialogListVisible: false,
            couponTypeList:[],
            // 选择商品参数
            chooseGoodsConfig: {
                type: ['chooseGoods'],
                model: 'normal',
                unique: false,
                thumbtn: 'thumbtns',
                initList: [],
            },
            // 选择图片
            chooseFilesImages: {
                type: ['image'],
                model: 'display',
                uploadConfig: {
                limit: 1,
                isMore: true,
                model: 'display'
                },
                isUnique: true,
                initList: [],
                isShowList: true,
                file_type: 'image',
                bindKey: {
                key: 'image_id',
                model: 'img'
                }
            },
            chooseFilesImage: {
                type: ['image'],
                model: 'display',
                uploadConfig: {
                limit: 1,
                isMore: true,
                model: 'display'
                },
                isUnique: true,
                initList: [],
                isShowList: true,
                file_type: 'image',
                bindKey: {
                key: 'image_id',
                model: 'img'
                }
            },
            //背景音乐
            choosePlatmaginConfig:{
                type: ['audio'],
                model: 'display',
                uploadConfig: {
                limit: 1,
                isMore: true,
                model: 'display'
                },
                initList: [],
                isShowList: true,
                file_type: 'audio',
                bindKey: {
                key: 'praise_music',
                model: 'img'
                }
            },
            //活动封面图
            choosePlatformConfig: {
                type: ['image'],
                model: 'display',
                uploadConfig: {
                limit: 1,
                isMore: true,
                model: 'display'
                },
                initList: [],
                isShowList: true,
                file_type: 'image',
                bindKey: {
                key: 'praise_img',
                model: 'img'
                }
            },
            choosePlatsappConfig: {
                type: ['image'],
                model: 'display',
                uploadConfig: {
                limit: 1,
                isMore: true,
                model: 'display'
                },
                initList: [],
                isShowList: true,
                file_type: 'image',
                bindKey: {
                key: 'praise_sapp_img',
                model: 'img'
                }
            },
            choosePlatwechatConfig: {
                type: ['image'],
                model: 'display',
                uploadConfig: {
                limit: 1,
                isMore: true,
                model: 'display'
                },
                initList: [],
                isShowList: true,
                file_type: 'image',
                bindKey: {
                key: 'praise_wechat_img',
                model: 'img'
                }
            },
            tableFormatData: {
                current: 'userTable',
                userTable: {
                key: 'userTable',
                api: {
                    getList: businessIndex
                },
                tableData: [],
                periods:[],
                files: {
                    name: '',
                    bus_id: '',
                    ids: [],
                    checkall: '0',
                    Recycle: '1',
                    praise_id:this.$route.query.praise_id?this.$route.query.praise_id:''
                },
                pagination: {
                    page: 1,
                    list_rows: 10,
                    pagesizes: [10, 20, 50],
                    total: 0
                }
                }
            },
            formFormatData: {
              key:['basicset','active'],
              api:{
                  editForm:{
                      api:praiseDetail,
                      params:{
                          praise_id:''
                      },
                      redirect: 'praise_id',
                    filters: {
                            img: {
                                bindInit: ['choosePlatformConfig','choosePlatsappConfig','choosePlatwechatConfig','choosePlatmaginConfig']
                            },
                            choose: {
                                bindInit: ['chooseGoodsConfig']
                            },
                          
                        },
                  },
                //   submitForm:praiseSave
                },
              formData: {
                prize_price:'',
                praise_wechat_text:'',
                is_false_look:2,
                false_look_rand:0,
                is_false_forward:2,
                false_look_num:'',
                false_forward_rand:0,
                false_user_num:'',
                false_forward_num:'',
                praise_sapp_img:[],
                praise_wechat_img:[],
                praise_img:[],
                praise_music:[],
                title:'', //活动名称
                time:[], //活动时间
                source:[], //活动渠道
                is_subscribe:1, //是否强制关注公众号 1是 2否
                user_group:1,  //抽奖人群
                label_ids:[],  //用户标签选项
                community:[],// 选中的社群ID
                content:'', //活动内容
                is_coupon:2, //1开启 2关闭
                address:'',
                coupon:[{praise_number:'',coupon_id:'',count:''}], //优惠券礼品项
                praise_number:'',
                type:1, //奖品模式 1名次 2 点赞
                rank:'', //前几名可以获奖
                SelectTabs:[], //标签设置选择的标签
                goods:[], //选中的商品信息
                prize: [],
                image: [],
                label:[],
              },
              rules: {
                title:[{
                  message:'请填写活动名称',
                  required: true,
                  trigger: 'change',
                  
                }],
              },
            }
          }
      },
      computed:{
        //   计算点赞前多少名可获奖，列表名次中就展示多少名
          rankingList(){
              var rankingList = []
              for(var i = 1;i<=this.formFormatData.formData.rank;i++){
                rankingList.push({label:`第${i}名`,value:i})
              }
              return rankingList
          }
      },
       mounted() {
    this.$nextTick(() => {
      setTimeout(() => {
        this.isFirst = true
      }, 500)
 
    })
  },
      methods: {
          praiseDetailbtn(){
              this.loading = true
              this.butt = true
              praiseDetail({praise_id:this.$route.query.praise_id}).then(res=>{
                  console.log("res++++++++++++++++++++++",res.data.data.praise_sapp_img)
                  console.log("res-------------------",this.formFormatData.formData)
                if(res.data.code==1){

                     
                //        praise_sapp_img:[],
                // praise_wechat_img:[],
                // praise_img:[],
                      this.formFormatData.formData = res.data.data
                     this.formFormatData.formData.praise_sapp_img = res.data.data.praise_sapp_img
                     this.formFormatData.formData.praise_wechat_img = res.data.data.praise_wechat_img
                     this.formFormatData.formData.praise_img = res.data.data.praise_img
                     this.formFormatData.formData.praise_music = res.data.data.praise_music
                      this.defaultMsg1=res.data.data.content
                      this.loading = false
                      this.butt = false
                      console.log("this.formFormatData.formData.praise_sapp_img ++++++++++++++++",this.formFormatData.formData.praise_sapp_img )
   
                      

                      console.log('this.formFormatData.formData',this.formFormatData.formData);
                  }
              })
          },
          superpositionbtn(is_superposition){
              if(is_superposition==1){
                 this.$confirm('开启叠加后相应的奖品可以叠加获取，例如点赞数50且开启叠加，点赞数60开启叠加，那么点赞数达60时可以叠加获取点赞数50和60的两个奖品；点赞数50且开启叠加，点赞数60不开启叠加，点赞数70开启叠加，那么点赞数达60可以获取点赞数50，60两个奖品，点赞数达70可以获取点赞数50，70两个奖品，以此类推', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                        customClass:'superposition'
                        }).then(() => {
                           
                        }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消删除'
                        });          
                        });
                }
          },
          delMeal(index){
                if(this.$route.query.status==1){
                   this.$confirm('正在进行中的活动删除优惠券后会对参与的用户造成影响?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                        }).then(() => {
                           this.formFormatData.formData.coupon.splice(index,1)
                        }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消删除'
                        });          
                        });
              }else{
                  if(this.formFormatData.formData.coupon.length<2){
                      return this.$message.error('操作失败！,至少保留一项')
                  }else{
                 this.formFormatData.formData.coupon.splice(index,1)
                  }
              }
          },
          //请求优惠券接口
          coupontableList(){
              couponEasyList().then(res=>{
                  console.log("9888888888888888",res.data.data)
                  this.couponTypeList = res.data.data
              })
          },
          deleteGiftTable(scope) {
             if(this.$route.query.status==1){
                   this.$confirm('正在进行中的活动删除奖品后会对参与的用户造成影响?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                        }).then(() => {
                           this.formFormatData.formData.prize.splice(scope.$index, 1)
                        }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消删除'
                        });          
                        });
              }else{
                 this.formFormatData.formData.prize.splice(scope.$index, 1)
              }
            },
          storeChange(val) {
                this.formFormatData.formData.prize[this.$lineIndex]['store_ids'] = []
                val.map(item => {
                    this.formFormatData.formData.prize[this.$lineIndex]['store_ids'].push({ id: item.id, name: item.name })
                })
                },
           showDialogSetDoor(data, bus_id) {
                this.$lineIndex = data
                this.formType = '2'
                this.tableFormatData.userTable.files.bus_id = bus_id
                this.tableFormatData.userTable.api.getList = shopIndex
                this.filesSerch()
                this.dialogListVisible = true
                },
          clearData() {
            this.lastID = -1
            },
            tableRowClassName({ row, rowIndex }) {
                if (row.storenum === 0) {
                    return 'disable-row'
                }
                return ''
                },
            merchantRowClick(row) {
            if (this.lastID !== row.id) {
                this.lastID = row.id
                if (row.storenum === 0) {
                console.log('22')
                this.$message({
                    message: '该商家没有门店~',
                    type: 'warning'
                })
                } else {
                const tableItem = this.formFormatData.formData.prize[this.$lineIndex]
                tableItem['bus_id'] = row.id
                tableItem['business_name'] = row.name
                tableItem['store_ids'] = []
                this.formFormatData.formData.prize.splice(this.$lineIndex, 1, tableItem)
                }
            }
            },
          showDialogSet(data) {
                this.$lineIndex = data
                this.formType = '1'
                this.tableFormatData.userTable.api.getList = businessIndex
                this.filesSerch()
                this.dialogListVisible = true
                },
          //删除标签设置数据
          delbtn(scope){
              if(this.$route.query.status==1){
                   this.$confirm('正在进行中的活动删除标签后会对参与的用户造成影响?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                        }).then(() => {
                            this.formFormatData.formData.label.splice(scope.$index,1)
                        }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消删除'
                        });          
                        });
              }else{
                  this.formFormatData.formData.label.splice(scope.$index,1)
              }
          },
        //   添加标签
        tagbtn(){
             this.formFormatData.formData.label.push({praise_num:'',label_ids:[]})
        },
          shopInfoChange(msg) {
            this.defaultMsg1 = msg
            },
             formFormatCallBack(data, type, response) {
                if (type === 'editForm') {
                    const { content } = data
                    this.defaultMsg1 = content
                }
            },
          //请求社群接口
          communitybtn(){
            servicesList({list_rows: 'all' }).then(res=>{
                this.selectValue = res.data.data
            })
            },
           // 点击标签用户请求接口
            luckcrowdbtn() {
            getUserTag().then(res => {
                const { data: { data: msgData = [] } } = res
                this.options = msgData
            })
            },
          //控制商品弹出框的显示
          goodsToogle() {
              this.$refs.chooseGoods.toggle()
          },
          //   增加优惠券礼品项
          addPrizeClick() {
              let obj = {praise_number:'',coupon_id:'',count:''}
              this.formFormatData.formData.coupon.push(obj)
          },
         //   构造商品信息
          filtersChange(val) {
            this.currentRow = val.currentRow
            const displayData = val.displayData
            const result = []
            displayData.map(item => {
                const newData = { image: [{ file_path: item.image[0]['file_path'] }],goods_name: item.goods_name, goods_id: item.goods_id, stock_num: item.stock, goods_price: item.goods_min_price }
                result.push({ goods:newData, goods_id: item.goods_id })
            })
            this.formFormatData.formData.goods = result
          },
        //  删除选中的商品
          deleteTable(scope) {
            this.formFormatData.formData.goods.splice(scope.$index, 1)
            this.currentRow.splice(scope.$index, 1)
          },
           // 点击图片出现弹窗
          uploadChange({ displayData = [] }) {
            this.formFormatData.formData.prize[this.$index].image = displayData
          },
          uploadColumn(index) {
            this.$index = index
            this.$refs.chooseFiles.toggle()
          },
             rankingbtn($event,scopedata){
            if(!$event){
               console.log("ddddaaaaaaaaaaaaadffffffffffff",$event,scopedata)
            }
                 console.log("ddddaaaaaaaaaaaaadffffffffffff",$event,scopedata)
          },
          addGiftTable() {
              if(this.formFormatData.formData.type == 1) {
                  this.formFormatData.formData.prize.push({ bus_id: '', store_ids: [], business_name: '', image: '',prize_hx_time_over:1,prize_hx_time:'' , title: '',ranking:'' })
              }else if (this.formFormatData.formData.type == 2) {
                  this.formFormatData.formData.prize.push({ bus_id: '', open_overlay:'', store_ids: [], business_name: '',prize_hx_time_over:1,prize_hx_time:'', image: '',  title: '',like_num:'' })
              }
          },
          //点击保存按钮
          saveForm() {
            //   富文本赋值
               this.formFormatData.formData.content = this.defaultMsg1
               this.butt = true
               //在提交保存前判断是否选择优惠券
               this.formFormatData.formData.coupon.forEach(res=>{
                     if(res.coupon_id=='' && this.formFormatData.formData.is_coupon==1){
                   this.$message.error('请选择优惠券！')
                   return
               }
               })
               const data = Base64.encode(JSON.stringify(this.formFormatData.formData))
                // const data = Base64.encode(JSON.stringify(this.formFormatData.formData))

               console.log("ssssssssssssss+++++++++++++++++++++",this.formFormatData.formData.prize)
            //    this.formFormatData.formData.prize.forEach(item =>{
            //        console.log("999999999999++++++++++++++++++++",item)
            //        item.store_ids.forEach(res=>{
                       
            //        })
            //    })
            // return ;
            //判断是否是编辑
            if(this.$route.query.praise_id){
                     praiseSave({data}).then(res=>{
                        const { data: { code, msg } } = res
                        if(code==1){
                            this.butt= false
                            this.$message({
                                type: 'success',
                                message: '修改成功!'
                            })
                            this.$router.push('/application/activityLike')
                        }else{
                            this.butt= false
                            this.$message.error(msg)
                        }
                    }).finally(()=>{
                         this.butt= false
                    })
            }else{
                  praiseSave({data}).then(res=>{
                   const { data: { code, msg } } = res
                         if(code==1){
                             this.butt = false
                            this.$message({
                                type: 'success',
                                message: '保存成功!'
                            })
                            this.$router.push('/application/activityLike')
                        }else{
                            this.butt = false
                            this.$message.error(msg)
                        }
                }).finally(()=>{
                    this.butt= false
                })
            }
            // if(this.$route.query.status=3){
            //     this.$message.error('活动已结束，无法进行保存！')
            // }
          },
      },
  }
</script>

<style lang="scss" scoped>
$update: 50px;
.update-load {
    display: inline-block;
    cursor: pointer;
    width: $update;
    height: $update;
    background: #fafbff;
    border: 1px dashed #c0ccda;
    color: #a8abb0;
    border-radius: 5px;

    i {
      font-size: 14px;
      color: #8c939d;
      width: $update;
      height: $update;
      line-height: $update;
      text-align: center;
    }
    .el-select-dropdown{
      max-width: 243px;
    }
    .el-select-dropdown__item{
      display:inline-block;
    }
    .el-select-dropdown__item span{
      min-width: 205px;
      display: inline-block;
    }
  
  }
</style>